package com.jdd.modules.area.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jdd.common.constant.CacheConstant;
import com.jdd.modules.area.entity.ChargeRules;
import com.jdd.modules.area.mapper.ChargeRulesMapper;
import com.jdd.modules.area.service.IChargeRulesService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * @Description: 停车场计费规则表
 * @Author: jdd
 * @Date:   2021-07-13
 * @Version: V1.0
 */
@Service
public class ChargeRulesServiceImpl extends ServiceImpl<ChargeRulesMapper, ChargeRules> implements IChargeRulesService {


    @Resource
    ChargeRulesMapper chargeRulesMapper;

    /**
     * 得到计费规则
     * @param carTypeId 车辆类型id
     * @param areaId 区域id
     * @return 计费规则
     * @date 2021-08-10 16:36
     * @author: liuyaowen
     * */
    @Override
    public ChargeRules getChargeRules(String carTypeId,String areaId) {
        LambdaQueryWrapper<ChargeRules> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ChargeRules::getCarTypeId,carTypeId);
        queryWrapper.eq(ChargeRules::getAreaId,areaId);
        return this.getOne(queryWrapper);
    }

    @Override
    public boolean updateById(ChargeRules chargeRules){
        return super.updateById(chargeRules);
    }

    @Override
    public boolean save(ChargeRules chargeRules) {
        return super.save(chargeRules);
    }

    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    /**
     * 清空表数据
     *
     * @return true 清空成功
     */
    @Override
    public boolean removeAllInfo() {
        try {
            chargeRulesMapper.removeAllInfo();
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
